package com.hyhy.hycloud.uaa.rpc.dubbo;

import com.hyhy.hycloud.uaa.exception.BadRequestSignatureException;
import com.hyhy.hycloud.uaa.rpc.InvalidRequestSignatureException;
import com.hyhy.hycloud.uaa.rpc.RequestSignatureServiceApi;
import com.hyhy.hycloud.uaa.service.RequestSignatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * RequestSignatureServiceApi Dubbo实现
 *
 * @author Xuegui Yuan
 * @date 2018-12-12
 */
@Service
public class RequestSignatureDubboService implements RequestSignatureServiceApi {
    @Autowired
    RequestSignatureService requestSignatureService;

    @Override
    public String genRequestId() {
        return requestSignatureService.genRequestId();
    }

    @Override
    public String genSignature(String bizCode, String requestId) {
        return requestSignatureService.genSignature(bizCode, requestId);
    }

    @Override
    public void checkSignature(String bizCode, String requestId, String signature) throws InvalidRequestSignatureException {
        try {
            requestSignatureService.checkSignature(bizCode, requestId, signature);
        } catch (BadRequestSignatureException e) {
            throw new InvalidRequestSignatureException(e.getErrorCode(), e.getMessage());
        }
    }
}
